home *** CD-ROM | disk | FTP | other *** search
/ Take-Home Tutor en Espanol / TakeHomeTutor.iso / pc / En espanol / Take-Home Tutor 3 / template5.swf / scripts / frame_2 / DoAction.as
Encoding:
Text File  |  2003-10-07  |  14.1 KB  |  486 lines

  1. function loadActivity(fname)
  2. {
  3.    t = getTimer();
  4.    ai.load(fname);
  5. }
  6. function setActivityInfo(_ai)
  7. {
  8.    ai = _ai;
  9.    render();
  10.    return true;
  11. }
  12. function render()
  13. {
  14.    delete this.answerList;
  15.    this.answerList = new Array();
  16.    layoutInfo.qTextFormat.align = "left";
  17.    if(parseInt(ai.type.text) == master.activityTypes.MULTI)
  18.    {
  19.       this.isMulti = true;
  20.    }
  21.    clearClip();
  22.    var tableY = layoutInfo.box.y;
  23.    var rightSideBuffer = layoutInfo.rightSideBuffer;
  24.    var topBuffer = 0;
  25.    if(ai.videoFile)
  26.    {
  27.       tableY = layoutInfo.temp4InstY;
  28.       topBuffer = master.videoPlayer._height;
  29.       rightSideBuffer = 250;
  30.    }
  31.    else if(ai.artFile)
  32.    {
  33.       rightSideBuffer = 250;
  34.    }
  35.    trace(this + ".render: called");
  36.    var title_mc;
  37.    var inst_mc;
  38.    if(ai.titleSpanish)
  39.    {
  40.       title_mc = createTitleField(ai.titleSpanish);
  41.       title_mc._x = layoutInfo.box.x;
  42.       title_mc._y = layoutInfo.box.y + topBuffer;
  43.       tableY = title_mc._y + title_mc._height;
  44.    }
  45.    if(ai.instructionsEnglish || ai.instructionsSpanish)
  46.    {
  47.       inst_mc = this.createInstructionField(this,"inst",ai.instructionsEnglish);
  48.       inst_mc._x = layoutInfo.box.x;
  49.       inst_mc._y = title_mc == null ? tableY : title_mc._y + title_mc._height;
  50.       trace("INST Y: " + inst_mc._y);
  51.       tableY = inst_mc._y + inst_mc._height;
  52.       trace("tableY (first check): " + tableY);
  53.    }
  54.    if(ai.videoFile == null && _parent.actNumber_mc._height > inst_mc._height + title_mc._height)
  55.    {
  56.       tableY = _parent.actNumber_mc._y + _parent.actNumber_mc._height + 10;
  57.    }
  58.    tableY = tableY != 0 ? tableY : layoutInfo.box.y;
  59.    trace("tableY: " + (tableY + topBuffer));
  60.    trace("rightSideBuffer: " + rightSideBuffer);
  61.    table = new TableClass(this);
  62.    tables = new Array();
  63.    atables = new Array();
  64.    if(!(ai.questions.question instanceof Array))
  65.    {
  66.       var tempa = new Array();
  67.       tempa.push(ai.questions.question);
  68.       ai.questions.question = tempa;
  69.    }
  70.    var qlen = ai.questions.question.length;
  71.    var qtc;
  72.    var qtr;
  73.    var answerChoices;
  74.    var answerText;
  75.    var question;
  76.    var answer;
  77.    var checkbox;
  78.    var feedbackCheck;
  79.    var mcon;
  80.    var i = 0;
  81.    while(i < qlen)
  82.    {
  83.       mcon = this.createEmptyMovieClip("qcon" + i,5000 + i);
  84.       var questionText;
  85.       var answerText1;
  86.       var answerText2;
  87.       questionText = ai.questions.question[i].questionText.text;
  88.       question = createQuestionField(mcon,i,replaceBlanks(questionText,8));
  89.       tables[i] = new TableClass();
  90.       qtc = new TableCell(question);
  91.       qtr = new TableRow();
  92.       qtr.addCell(qtc);
  93.       tables[i].addRow(qtr);
  94.       atables[i] = new TableClass();
  95.       answerChoices = ai.questions.question[i].answerChoice;
  96.       var j = 0;
  97.       while(j < answerChoices.length)
  98.       {
  99.          answerText = answerChoices[j];
  100.          feedbackCheck = mcon.attachMovie("check","correctcheck_" + i + "_" + j,PMSI.DepthManager.getNextDepth());
  101.          checkbox = mcon.attachMovie("radiobutton","check_" + i + "_" + j,PMSI.DepthManager.getNextDepth());
  102.          answerList.push(checkbox);
  103.          checkbox.feedbackCheck = feedbackCheck;
  104.          checkbox.onRelease = answerOnRelease;
  105.          checkbox.groupId = i;
  106.          if(answerText.text == ai.questions.question[i].correctAnswer.text)
  107.          {
  108.             checkbox.isCorrectAnswer = true;
  109.          }
  110.          else
  111.          {
  112.             checkbox.isCorrectAnswer = false;
  113.          }
  114.          answer = createAnswerField(mcon,j,0,answerText);
  115.          qtr = new TableRow();
  116.          qtc = new TableCell(feedbackCheck);
  117.          qtr.addCell(qtc);
  118.          qtc = new TableCell(checkbox);
  119.          qtr.addCell(qtc);
  120.          qtc = new TableCell(answer);
  121.          qtr.addCell(qtc);
  122.          atables[i].addRow(qtr);
  123.          j++;
  124.       }
  125.       i++;
  126.    }
  127.    trace("tableY: " + tableY);
  128.    var tableWidth = layoutinfo.MAX_WIDTH - rightSideBuffer;
  129.    trace("layoutinfo.MAX_WIDTH: " + layoutinfo.MAX_WIDTH);
  130.    trace("rightSideBuffer " + rightSideBuffer);
  131.    trace("TABLE WIDTH: " + tableWidth);
  132.    var ttab;
  133.    var atab;
  134.    var tableY1 = tableY;
  135.    var tableY2 = tableY;
  136.    var maxHeight = 0;
  137.    var divsor = atables.length <= 3 ? 1 : 2;
  138.    var i = 0;
  139.    while(i < tables.length)
  140.    {
  141.       trace("i: " + i);
  142.       ttab = tables[i];
  143.       ttab.setPosition({x:0,y:0});
  144.       ttab.setCellSpacing(6);
  145.       ttab.init();
  146.       ttab.setWidth(tableWidth / divsor);
  147.       trace(ttab.height);
  148.       tableY1 += ttab.height;
  149.       trace("ASDA: " + ttab.width);
  150.       atab = atables[i];
  151.       atab.setPosition({x:0,y:ttab.height + 4});
  152.       atab.setCellSpacing(6);
  153.       atab.init();
  154.       atab.setWidth(tableWidth / divsor);
  155.       trace(atab.height);
  156.       tableY1 += atab.height - 30;
  157.       if(maxHeight < ttab.height + atab.height)
  158.       {
  159.          maxHeight = ttab.height + atab.height;
  160.       }
  161.       trace("maxHeight: " + maxHeight);
  162.       i++;
  163.    }
  164.    biglayout = new TableClass();
  165.    qtr = new TableRow();
  166.    qtc = new TableCell(qcon0);
  167.    qtr.addCell(qtc);
  168.    qtc = new TableCell(qcon1);
  169.    qtr.addCell(qtc);
  170.    biglayout.addRow(qtr);
  171.    qtr = new TableRow();
  172.    qtc = new TableCell(qcon2);
  173.    qtr.addCell(qtc);
  174.    qtc = new TableCell(qcon3);
  175.    qtr.addCell(qtc);
  176.    biglayout.addRow(qtr);
  177.    qtr = new TableRow();
  178.    qtc = new TableCell(qcon4);
  179.    qtr.addCell(qtc);
  180.    qtc = new TableCell(qcon5);
  181.    qtr.addCell(qtc);
  182.    biglayout.addRow(qtr);
  183.    biglayout.setPosition({x:layoutInfo.box.x,y:tableY});
  184.    biglayout.setCellSpacing(20);
  185.    biglayout.init();
  186. }
  187. function answerOnRollOver()
  188. {
  189.    this.gotoAndStop("rollOver");
  190. }
  191. function answerOnRollOut()
  192. {
  193.    this.gotoAndStop("rollOut");
  194. }
  195. function answerOnRelease()
  196. {
  197.    if(this._parent._parent.isMulti)
  198.    {
  199.       var groupId = this.groupId;
  200.       var gmem;
  201.       var i = 0;
  202.       while(true)
  203.       {
  204.          gmem = this._parent["check_" + groupId + "_" + i];
  205.          if(gmem == null)
  206.          {
  207.             break;
  208.          }
  209.          trace(gmem);
  210.          if(gmem != this)
  211.          {
  212.             gmem.gotoAndStop("notSelected");
  213.             gmem.isSelected = false;
  214.          }
  215.          i++;
  216.       }
  217.    }
  218.    trace(this + ": " + this.isSelected);
  219.    if(!this.isSelected || this.isSelected == null)
  220.    {
  221.       this.isSelected = true;
  222.       this.gotoAndStop("selected");
  223.    }
  224.    else
  225.    {
  226.       this.isSelected = false;
  227.       this.gotoAndStop("notSelected");
  228.    }
  229. }
  230. function createInstructionField(cnt, name, text)
  231. {
  232.    var mc = cnt.createEmptyMovieClip(name,PMSI.DepthManager.getNextDepth());
  233.    mc.createTextField("content",PMSI.DepthManager.getNextDepth(),0,0,0,0);
  234.    var tf = layoutInfo.instTextFormat;
  235.    mc.content.embedFonts = true;
  236.    mc.content.border = false;
  237.    mc.content.type = "dynamic";
  238.    mc.content.text = text;
  239.    mc.content.setTextFormat(tf);
  240.    mc.content._height = 400;
  241.    mc.content.wordWrap = true;
  242.    mc.content.color = layoutInfo.instTextColor;
  243.    mc.content._width = 300;
  244.    mc.content.autoSize = true;
  245.    mc.content.selectable = false;
  246.    return mc;
  247. }
  248. function createQuestionField(cnt, id, text)
  249. {
  250.    var mc = cnt.createEmptyMovieClip("question" + id,PMSI.DepthManager.getNextDepth());
  251.    mc.createTextField("content",PMSI.DepthManager.getNextDepth(),0,0,0,0);
  252.    var tf = layoutInfo.qTextFormat;
  253.    mc.content.embedFonts = true;
  254.    mc.content.border = TXT_DEBUG_SHOW_BORDERS;
  255.    mc.content.type = "dynamic";
  256.    mc.content.text = text;
  257.    mc.content.autoSize = true;
  258.    mc.content.setTextFormat(tf);
  259.    mc.content.selectable = false;
  260.    return mc;
  261. }
  262. function createAnswerField(cnt, id, subid, text)
  263. {
  264.    var amc1 = cnt.createEmptyMovieClip("answer" + subid + "_" + id,PMSI.DepthManager.getNextDepth());
  265.    amc1.createTextField("content",PMSI.DepthManager.getNextDepth(),0,0,0,0);
  266.    var tf2 = layoutInfo.answerTextFormat1;
  267.    amc1.content.embedFonts = true;
  268.    amc1.content.border = TXT_DEBUG_SHOW_BORDERS;
  269.    amc1.content.type = "dynamic";
  270.    amc1.content.text = text;
  271.    amc1.content.autoSize = true;
  272.    amc1.content.selectable = false;
  273.    amc1.content.setTextFormat(tf2);
  274.    return amc1;
  275. }
  276. function createAnswerSpacer(cnt, id)
  277. {
  278.    var amcSpacer = cnt.createEmptyMovieClip("answerSpacer_" + id,PMSI.DepthManager.getNextDepth());
  279.    amcSpacer.createTextField("content",PMSI.DepthManager.getNextDepth(),0,0,0,0);
  280.    var tf2 = layoutInfo.answerTextFormat1;
  281.    amcSpacer.content.embedFonts = true;
  282.    amcSpacer.content.border = TXT_DEBUG_SHOW_BORDERS;
  283.    amcSpacer.content.type = "dynamic";
  284.    amcSpacer.content.text = "  ";
  285.    amcSpacer.content.autoSize = true;
  286.    amcSpacer.content.setTextFormat(tf2);
  287.    amcSpacer.content.selectable = false;
  288.    return amcSpacer;
  289. }
  290. function checkAnswers()
  291. {
  292.    var qlen = ai.questions.question.length;
  293.    var correct = 0;
  294.    var clp;
  295.    var i = 0;
  296.    while(i < answerList.length)
  297.    {
  298.       clp = answerList[i];
  299.       if(clp.isSelected && clp.isCorrectAnswer)
  300.       {
  301.          correct++;
  302.          clp.feedbackCheck.gotoAndStop("correct");
  303.       }
  304.       else if(clp.isSelected && !clp.isCorrectAnswer)
  305.       {
  306.          clp.feedbackCheck.gotoAndStop("incorrect");
  307.       }
  308.       else
  309.       {
  310.          clp.feedbackCheck.gotoAndStop(1);
  311.       }
  312.       i++;
  313.    }
  314.    master.setFeedback(correct,qlen);
  315. }
  316. function createTitleField(txt)
  317. {
  318.    var mc = this.createEmptyMovieClip("title",PMSI.DepthManager.getNextDepth());
  319.    mc.createTextField("content",PMSI.DepthManager.getNextDepth(),0,0,0,0);
  320.    var tf = layoutInfo.titleTextFormat;
  321.    mc.content.embedFonts = true;
  322.    mc.content.border = false;
  323.    mc.content.type = "dynamic";
  324.    mc.content.text = txt;
  325.    mc.content.setTextFormat(tf);
  326.    mc.content.wordWrap = true;
  327.    mc.content.color = layoutInfo.instTextColor;
  328.    mc.content._width = 300;
  329.    mc.content.autoSize = true;
  330.    mc.content.selectable = false;
  331.    return mc;
  332. }
  333. function highlightIncorrect(text)
  334. {
  335. }
  336. function clearClip()
  337. {
  338.    layoutInfo.qMaxWidthPos = 0;
  339.    layoutInfo.qMaxWidth = 0;
  340.    layoutInfo.a1MaxWidth = 0;
  341.    layoutInfo.a2MaxWidth = 0;
  342.    for(var mc in this)
  343.    {
  344.       if(this[mc] != _parent && this[mc] != this)
  345.       {
  346.          this[mc].clear();
  347.          this[mc].removeMovieClip();
  348.       }
  349.    }
  350. }
  351. function drawDebugBox()
  352. {
  353.    this.lineStyle(1,16711680,100);
  354.    this.drawRect(layoutInfo.box.x,layoutInfo.box.y,layoutInfo.MAX_WIDTH,layoutInfo.MAX_HEIGHT);
  355. }
  356. function replaceBlanks(s_str, maxlen)
  357. {
  358.    trace("MAXLEN: " + maxlen);
  359.    var str = s_str.toString();
  360.    return replaceBlanksR(str,maxlen);
  361. }
  362. function replaceBlanksR(s_str, maxlen)
  363. {
  364.    trace(s_str);
  365.    var si = s_str.indexOf(TAGS.BLANK_OPEN);
  366.    if(si == -1)
  367.    {
  368.       return s_str;
  369.    }
  370.    var ei = s_str.indexOf(TAGS.BLANK_CLOSE) + TAGS.BLANK_CLOSE.length;
  371.    s_str = s_str.slice(0,si) + makeStringFromChar("_",maxlen) + s_str.slice(ei,s_str.length);
  372.    return replaceBlanks(s_str,maxlen);
  373. }
  374. function makeStringFromChar(char, length)
  375. {
  376.    var str = "";
  377.    var i = 0;
  378.    while(i < length)
  379.    {
  380.       str += char;
  381.       i++;
  382.    }
  383.    return str;
  384. }
  385. stop();
  386. var TXT_DEBUG_SHOW_BORDERS = false;
  387. var testFile1 = "activities/data/C1.U2.S3.EV.VA.7.xml";
  388. var testFile2 = "C1.U2.S3.VO.1.B2.xml";
  389. var testFile3 = "C1.U1.S2.GR.3.A1.xml";
  390. if(_parent)
  391. {
  392.    master = _parent;
  393. }
  394. else
  395. {
  396.    master = this;
  397. }
  398. if(master.layoutInfo == null)
  399. {
  400.    var layoutInfo = {};
  401.    layoutInfo.titleTextColor = 3636920;
  402.    layoutInfo.answerRollOverColor = 16695085;
  403.    layoutInfo.answerRollOutColor = 3636920;
  404.    layoutInfo.answerSelectColor = 2309272;
  405.    layoutInfo.questionTextColor = 2309272;
  406.    layoutInfo.instTextColor = 2309272;
  407.    layoutInfo.doAnswerFill = false;
  408.    layoutInfo.rightSideBuffer = 60;
  409.    layoutInfo.box = {};
  410.    layoutInfo.box.x = 260;
  411.    layoutInfo.box.y = 94;
  412.    layoutInfo.box.views = [];
  413.    layoutInfo.box.widthWithBox = 300;
  414.    layoutInfo.box.heightWithBox = 300;
  415.    layoutInfo.box.widthWithoutBox = 300;
  416.    layoutInfo.box.heightWithoutBox = 300;
  417.    layoutinfo.MAX_WIDTH = 520;
  418.    layoutInfo.MAX_HEIGHT = 380;
  419.    layoutInfo.questionIndent = 30;
  420.    layoutInfo.selectionRadius = 6;
  421.    layoutInfo.drawSelectionCircle = true;
  422.    layoutInfo.lineSpacing = 5;
  423.    layoutInfo.selectionBorderThickness = 1;
  424.    layoutInfo.instTextFormat = new TextFormat();
  425.    layoutInfo.instTextFormat.font = "Formata_Bold";
  426.    layoutInfo.instTextFormat.size = 12;
  427.    layoutInfo.instTextFormat.color = layoutInfo.instTextColor;
  428.    layoutInfo.qTextFormat = new TextFormat();
  429.    layoutInfo.qTextFormat.font = "Formata_Normal";
  430.    layoutInfo.qTextFormat.size = 12;
  431.    layoutInfo.qTextFormat.color = layoutInfo.questionTextColor;
  432.    layoutInfo.qTextFormat.align = "right";
  433.    layoutInfo.answerTextFormat1 = new TextFormat();
  434.    layoutInfo.answerTextFormat1.font = "Formata_Normal";
  435.    layoutInfo.answerTextFormat1.size = 12;
  436.    layoutInfo.answerTextFormat1.color = layoutInfo.answerRollOutColor;
  437.    layoutInfo.answerTextFormat2 = new TextFormat();
  438.    layoutInfo.answerTextFormat2.font = "Formata_Normal";
  439.    layoutInfo.answerTextFormat2.size = 12;
  440.    layoutInfo.answerTextFormat2.color = layoutInfo.answerRollOutColor;
  441.    layoutInfo.titleTextFormat = new TextFormat();
  442.    layoutInfo.titleTextFormat.font = "TriplexCondSerifBlack";
  443.    layoutInfo.titleTextFormat.size = 24;
  444.    layoutInfo.titleTextFormat.color = layoutInfo.titleTextColor;
  445. }
  446. else
  447. {
  448.    layoutInfo = master.layoutInfo;
  449. }
  450. layoutInfo.temp4InstWidth = 250;
  451. layoutInfo.temp4InstY = 305;
  452. var ai = new ActivityInfo();
  453. ai._parent = this;
  454. ai.onLoad = function(success)
  455. {
  456.    trace("id:   " + this.getIdString());
  457.    trace("type: " + this.type);
  458.    var i = 0;
  459.    while(i < this.questions.question.length)
  460.    {
  461.       trace(i + 1 + ". " + this.questions.question[i].questionText);
  462.       i++;
  463.    }
  464.    this._parent.render();
  465.    trace("Time: " + (getTimer() - t) / 1000);
  466. };
  467. if(_parent == null)
  468. {
  469.    loadActivity(testFile1);
  470. }
  471. answer.onRelease = function()
  472. {
  473.    checkAnswers();
  474. };
  475. answer.onRollOver = function()
  476. {
  477.    this.gotoAndStop("rollOver");
  478. };
  479. answer.onRollOut = function()
  480. {
  481.    this.gotoAndStop("rollOut");
  482. };
  483. TAGS = {};
  484. TAGS.BLANK_OPEN = "[:blank:]";
  485. TAGS.BLANK_CLOSE = "[:/blank:]";
  486.